package cn.gok.common.dao.backstage;

import cn.gok.common.entity.backstage.SysUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface SysUserMapper extends BaseMapper <SysUser> {


    /**
     * 通过用户编号获取用户的角色名称
     *
     * @param id 用户编号
     * @return 角色
     */
    @Select("SELECT " +
            "sr.ROLE_NAME " +
            "FROM " +
            "sys_user_role sur," +
            "sys_role sr " +
            "WHERE " +
            "sr.ROLE_ID = sur.ROLE_ID " +
            "AND sur.USER_ID = #{id}")
    String getRoleNameById(long id);

    /**
     * 获取用户的功能权限字串
     *
     * @param id 用户编号
     * @return 功能权限集合
     */
    @Select("SELECT " +
            "sm.PERMS " +
            "FROM " +
            "sys_menu sm," +
            "sys_role_menu srm," +
            "sys_user_role sur " +
            "WHERE " +
            "sm.MENU_ID = srm.MENU_ID " +
            "AND srm.ROLE_ID = sur.ROLE_ID " +
            "AND sur.USER_ID = #{id} " +
            "AND sm.PERMS != 'all'")
    List <String> getPermissionsById(long id);
}